package com.ybt.configration;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class YBTConfigration {
    private static Logger logger = Logger.getLogger(YBTConfigration.class);
    public Properties config = new Properties();
    private volatile static YBTConfigration rconfig;
    
    public static YBTConfigration getInstance(){
        if( rconfig == null){
            synchronized(YBTConfigration.class){
                if( rconfig == null){
                    rconfig = new YBTConfigration();
                }
            }
        }
        return rconfig;
    }
    
    private YBTConfigration (){
        try{
            String deployPath = System.getProperty(IYBTConfigration.WORKFLOW_DEPLOY_PATH);
            deployPath = "E:\\eclipse\\workspace\\YBT_Simple\\conf";
            logger.debug("workflow deploy path="+deployPath);
            config.load(new FileInputStream(new File(deployPath+"/conf/config.properties")));
            config.put(IYBTConfigration.WORKFLOW_DEPLOY_PATH, deployPath);
        }catch(Exception e){
            throw new RuntimeException("initional workflow configration error", e);
        }
    }
    
    public String getProperty(String key){
        return config.getProperty(key);
    }
    
    public void setProperty(String key, String value){
        config.setProperty(key, value);
    }
}
